package com.farm.controller;

import com.farm.common.R;
import com.farm.pojo.EsParam;
import com.farm.pojo.Vo.PolicyEsVo;
import com.farm.service.EsCommitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/commitEs")
@Slf4j
@RestController
public class EsController {
    @Autowired
    private EsCommitService esCommitService;


    /**
     * 搜索框自动补全功能
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    public R<List<Map<String, String>>> getSuggestion(@RequestParam String prefix,@RequestParam String path){
        if (prefix.equals("")){
            return  R.success(null);
        }
        log.info("我是自动补全的数据：" + prefix);
        List<Map<String, String>> list =  esCommitService.getSuggestion(prefix,path);
        return R.success(list);
    }

    /**
     * 获取政策搜索
     * @param esParam
     * @return
     */
    @PostMapping("/getPolicy")
    public R<List<PolicyEsVo>> getPolicy(@RequestBody EsParam esParam){
        log.info("开始es搜索：" + esParam);
        List<PolicyEsVo> policyEsVo =  esCommitService.getPolicy(esParam);
        return R.success(policyEsVo);
    }

}
